<template>
    <div>
        <m-table :columns="columns" ref="tableRef" :title="$route.meta.title" :pagination="false"
            :api="getPositionList">

            <template #button>
                <a-button type="primary" size="small" @click="handleEdit('add')" v-perms="['/adminapi/organize.position/save']">
                    <icon name="ant-icon-PlusOutlined" />
                </a-button>
            </template>

            <template #status="{ record }">
                <a-tag v-if="record.status" color="green">启用</a-tag>
                <a-tag v-else color="red">禁用</a-tag>
            </template>

            <template #action="{ record }">
                <a-space>
                    <a-button type="primary" size="small" @click="handleEdit('edit', record)" v-perms="['/adminapi/organize.position/update']">
                        <icon name="ant-icon-EditOutlined" />
                    </a-button>
                    <a-popconfirm title="确定删除吗？" @confirm="handleDelete(record.id)">
                        <a-button type="danger" size="small" v-perms="['/adminapi/organize.position/delete']">
                            <icon name="ant-icon-DeleteOutlined" />
                        </a-button>
                    </a-popconfirm>

                </a-space>
            </template>
        </m-table>
        <editPopup ref="editPopupRef" @success="tableRef?.run()" />
    </div>
</template>
<script setup lang="ts">
import { getPositionList , deletePosition } from '@/api/system/organize/position'
import editPopup from './components/edit.vue'
const editPopupRef = ref<InstanceType<typeof editPopup>>()
const columns = [
    { title: '职位名称', dataIndex: 'title', width: 200 },
    { title: '部门', dataIndex: 'department_id_name', width: 200 },
    { title: '负责人', dataIndex: 'leader_id_name', width: 200 },
    { title: '状态', dataIndex: 'status', width: 200 },
    { title: '创建时间', dataIndex: 'create_time', width: 200 },
    { title: '更新时间', dataIndex: 'update_time', width: 200 },
    { title: '操作', dataIndex: 'action', width: 200 },
]

const tableRef = ref();

const handleEdit = (mode: string, record?: any) => {
    editPopupRef.value?.open(mode, record)
}

const handleDelete = async (id: any) => {
    await deletePosition(id)
    tableRef.value?.run()
}
</script>
